(function ($) {
    function MsgManage(data, func) {
        switch (data.Statu) {
            case "ok":
                
                layer.msg(data.Msg, { icon: 1, time: 3000 }, function () {
                    if (window.name.indexOf("nameStorage") < 0) {
                        var index = parent.layer.getFrameIndex(window.name);
                        if (index != undefined && index > 0) {
                            layer.close(index);
                        }
                    }
                   
                    if (data.BackUrl != null && data.BackUrl != '' && data.BackUrl != undefined) {
                        window.location = data.BackUrl
                    }
                    if (typeof func === 'function') {
                       
                        func();
                    }
                    
                })
                break;
            case "okto":
                layer.msg(data.Msg, { icon: 1, time: 3000 }, function () {
                    if (window.name.indexOf("nameStorage") < 0) {
                        var index = parent.layer.getFrameIndex(window.name);
                        if (index != undefined && index > 0) {
                            parent.layer.close(index);
                        }
                    }
                    if (data.BackUrl != null && data.BackUrl != '' && data.BackUrl != undefined) {
                       window.location = data.BackUrl
                    }
                    if (typeof func === 'function') {
                        func();
                    }
                })
                break;
            case "f_okto":
                parent.window.location = data.BackUrl;
                break;
            case "err":
                layer.msg(data.Msg, { icon: 5, time: 3000 }, function () {
                    if (window.name.indexOf("nameStorage") < 0) {
                        var index = parent.layer.getFrameIndex(window.name);
                        if (index != undefined && index > 0) {
                            parent.layer.close(index);
                        }
                    }
                    if (data.BackUrl != null && data.BackUrl != '' && data.BackUrl != undefined) {
                        window.location = data.BackUrl
                    }
                    if (typeof func === 'function') {
                        func();
                    }
                })
                break;
            case "verr":
                var msg = "";
                if (data.Data.length > 0) {
                    for (i = 0; i < data.Data.length; i++) {
                        msg = msg + "\r\n" + data.Data[i].ValideErrMsg;
                    }
                    layer.alert(data.Msg, 3)
                    break;
                }
                layer.msg(data.Msg, 3, 3)
                break;
            case "errto":
                layer.alert(data.Msg, 3)
                window.location = data.BackUrl;
                break;
            case "redirect":
                window.location = data.BackUrl;
                break;
            case "onlogin":
                window.location = data.BackUrl;
                break;
            case "okpage":
                $("#tempTable tr:gt(0)").remove();
                $("#Tr").tmpl(data.Data.PageData).appendTo("#tempTable");
                createPager("pagebar", data.Data.RowCount, data.Data.PageSize, data.Data.PageIndex, getPageList);//生成页码条
                InitSerial(data.Data.PageIndex, data.Data.PageSize);
                //$.msgBox.hidBox();
                break;
        }
    }
    //列表中josn 时间转换
    function DateInitSerial(num) {
        // alert(num);
        $(".tablist tr").each(function () {
            var vl1 = $(this).find("td:eq(" + num + ")").html();
            if (vl1 != null && (/Date\(-\d{14}\)/.test(vl1) || /Date\(\d{13}\)/.test(vl1))) {
                var jsondate = new Date(parseInt(vl1.substring(6, vl1.length - 2)));
                $(this).find("td:eq(" + num + ")").html(jsondate.format("yyyy年MM月dd日"));
            }
        });
    };
    //josn 时间转换
    Date.prototype.format = function (format) {
        var o =
        {
            "M+": this.getMonth() + 1, //month
            "d+": this.getDate(),    //day
            "h+": this.getHours(),   //hour
            "m+": this.getMinutes(), //minute
            "s+": this.getSeconds(), //second
            "q+": Math.floor((this.getMonth() + 3) / 3),  //quarter
            "S": this.getMilliseconds() //millisecond
        }
        if (/(y+)/.test(format))
            format = format.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
        for (var k in o)
            if (new RegExp("(" + k + ")").test(format))
                format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));
        return format;
    }
    $.extend($, {
        Success: function (data, func) {
            //if (!data.Statu) {
            //    return;
            //}
            MsgManage(data, func);
        },
        Failure: function (data, funcErr) {
            MsgManage(data);
        }
    })
}(jQuery));